<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="application/msword; charset=utf-8"/>
    <title>toWord</title>
    <style type="text/css">

        body {
            font-family: SimSun, "Microsoft Yahei";
            font-size: 14px;
        }

        table {
            margin-bottom: 10px;
        }

        h1 {
            font-size: 32px;
        }

        h2 {
            font-size: 24px;
        }

        h3 {
            font-size: 18.7px;
        }

        p,pre {
            margin-left: 2em;
        }

        .bg {
            font-size: 14px;
            font-weight: bold;
            color: #000;
            background-color: #cccccc;
        }

        table {
            border: 0.67px solid black;
            table-layout: fixed;
            margin-left: 2em;
        }

        tr {
            min-height: 30px;
        }

        td {
            padding-left: 10px;
            overflow: hidden;
            word-break: break-all;
            word-wrap: break-word;
        }

    </style>
</head>

<body>
<div style="width:1000px;margin: 0 auto">
    <div>
        <h1 th:text="接口"></h1>
        <a th:if="${download == 1}" th:href="${'/downloadWord?url='+ url}">下载文档</a>
        <br>
    </div>
    <div th:each="tableMap:${tableMap}">
        <!--这个是类的说明-->
        <h2 th:text="${tableMap.key}"></h2>
        <div th:each="table,tableStat:${tableMap.value}">

            <!--这个是每个请求的说明，方便生成文档后进行整理-->
            <h3 th:text="${table.tag}"></h3>

            <div>
                <strong>接口说明</strong>
                <p th:text="${table.tag}"></p>
            </div>

            <div>
                <strong>URL</strong>
                <p th:text="${table.url}"></p>
            </div>

            <div>
                <strong>请求方法</strong>
                <p th:text="${table.requestType}"></p>
            </div>

            <div>
                <strong>请求/返回格式</strong>
                <p th:text="${'请求: '+table.requestForm}"></p>
                <p th:text="${'返回: '+table.responseForm}"></p>
            </div>

            <div>
                <strong>请求参数</strong>

                <table border="1" cellspacing="0" cellpadding="0" width="100%">

                    <tr class="bg">
                        <td>参数名</td>
                        <td width="29%">说明</td>
                        <td width="15%">数据类型</td>
                        <td width="15%">参数类型</td>
                        <td width="15%">是否必填</td>

                    </tr>

                    <th:block th:each="request, c:${table.requestList}">
                        <tr th:if="${request.paramType} != 'body'">
                            <td align="left" th:text="${request.name}"></td>
                            <td th:text="${request.remark}"></td>
                            <td th:text="${request.type}"></td>
                            <td th:text="${request.paramType}"></td>
                            <td th:if="${request.require}" th:text="是"></td>
                            <td th:if="${!request.require}" th:text="否"></td>
                        </tr>
                    </th:block>

                    <!--               对返回参数 递归生成行-->
                    <tbody th:include="this::request(${table.requestBody},'', 1)"/>

                </table>
            </div>

            <div>
                <strong>请求参数示例</strong>
                <pre th:text="${table.requestParam}"></pre>
            </div>

            <div>
                <strong>返回参数</strong>

                <table border="1" cellspacing="0" cellpadding="0" width="100%">

                    <tr class="bg">
                        <td>返回参数名</td>
                        <td width="30%"colspan="2">说明</td>
                        <td width="30%" colspan="2">类型</td>
                    </tr>

                    <!--               对返回参数 递归生成行-->
                    <tbody th:include="this::response(${table.modelAttr.properties},'', 1)"/>

                </table>
            </div>

            <div>
                <strong>返回参数示例</strong>
                <pre th:text="${table.responseParam}"></pre>
            </div>

        </div>
    </div>
</div>

<th:block th:fragment="request(properties,count, lv)">
    <th:block th:each="p,c : ${properties}">
        <tr>
            <td align="left" th:if="${lv} == 1" th:text="${p.name}"
                th:style="|padding-left:${10*lv}px|"></td>
            <td align="left" th:if="${lv} > 1" th:text="'- ' + ${p.name}"
                th:style="|padding-left:${10*lv}px|"></td>
            <td th:text="${p.description}"></td>
            <td th:text="${p.type}"></td>
            <td th:text="${p.paramType}"></td>
            <td th:if="${p.require}" th:text="是"></td>
            <td th:if="${!p.require}" th:text="否"></td>

        </tr>
        <th:block th:unless="${#lists.isEmpty(p.properties)}"
                  th:include="this::request(${p.properties},${count} + '' + ${c.count} + '.',${lv+1})"/>
    </th:block>
</th:block>

<th:block th:fragment="response(properties,count, lv)">
    <th:block th:each="p,c : ${properties}">
        <tr>
            <td align="left" th:if="${lv} == 1" th:text="${p.name}"
                th:style="|padding-left:${10*lv}px|"></td>
            <td align="left" th:if="${lv} > 1" th:text="'- ' + ${p.name}"
                th:style="|padding-left:${10*lv}px|"></td>
            <td colspan="2" th:text="${p.description}"></td>
            <td colspan="2" th:text="${p.type}"></td>
        </tr>
        <th:block th:unless="${#lists.isEmpty(p.properties)}"
                  th:include="this::response(${p.properties},${count} + '' + ${c.count} + '.',${lv+1})"/>
    </th:block>
</th:block>
</body>
</html>
